In programming, an indexer is in object-oriented programming a kind of smart array that enables the user to get an index of objects held within an object. It is a member of a class that enables the use it like an array. For instance, in C#, it is possible to access with an indexer a class like an array.[1]
Contents |
Indexers are implemented through the get and set accessors for the operator[]. They are similar to properties, but differ from them in not being static. The get and set accessors are called as methods using the parameter list of the indexer declaration, but the set accessor still has the implicite value parameter.
Here an example of the usage of an indexer in a class: [2]
class OurFamily { private long[] familyMember = new long[7]; public long this [int index] { // The get accessor get { return familyMember[index]; } // The set accessor with set { familyMember[index] = value; } } }